from fastapi import UploadFile, File

from img.ocr_img import ImgParser
from server import app, error, success


@app.post("/ocr/img")
async def ocr_img(mode: str, file: UploadFile = File(...)):
    parser = ImgParser()
    if not parser.can_parse(file.filename):
        return error(400, message="Invalid File")
    if mode is None or mode == '':
        return error(400, message="Invalid Mode")
    result = await parser.parse_upload_file_to_text(file, mode)
    return success(result)

